#pragma once

#include "DeploymentSpecification.h"

#include "Deployment.h"

namespace uml {

const QString DeploymentSpecification::deploymentLocation_default_ = "";
const QString DeploymentSpecification::executionLocation_default_ = "";
DeploymentSpecification::DeploymentSpecification(const QString& umlType)
    : Artifact(umlType) {}

void DeploymentSpecification::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    Artifact::fromJson(json, errorList);
    deployment_ = JsonSerializable::create<Deployment>(json.value("deployment"), errorList);

    deploymentLocation_ = json.value("deploymentLocation").toString(deploymentLocation_default_);
    executionLocation_ = json.value("executionLocation").toString(executionLocation_default_);
}

void DeploymentSpecification::toJson(QJsonObject& json) {
    Artifact::toJson(json);
    if (deployment_) {
        QJsonObject deployment_json;
        deployment_->toJson(deployment_json);
        json.insert("deployment", deployment_json);
    }
    if (deploymentLocation_ != deploymentLocation_default_) {
        json.insert("deploymentLocation", deploymentLocation_);
    }
    if (executionLocation_ != executionLocation_default_) {
        json.insert("executionLocation", executionLocation_);
    }
}

/// <summary>
/// deployment getter
/// The deployment with which the DeploymentSpecification is associated.
/// </summary>
shared_ptr<Deployment> DeploymentSpecification::deployment() const {
    return deployment_;
}

/// <summary>
/// deployment setter
/// The deployment with which the DeploymentSpecification is associated.
/// </summary>
void DeploymentSpecification::setDeployment(shared_ptr<Deployment> value) {
    deployment_ = value;
}

/// <summary>
/// deploymentLocation getter
/// The location where an Artifact is deployed onto a Node. This is typically a
/// 'directory' or 'memory address.'
/// </summary>
QString DeploymentSpecification::deploymentLocation() const {
    return deploymentLocation_;
}

/// <summary>
/// deploymentLocation setter
/// The location where an Artifact is deployed onto a Node. This is typically a
/// 'directory' or 'memory address.'
/// </summary>
void DeploymentSpecification::setDeploymentLocation(const QString& value) {
    deploymentLocation_ = value;
}

/// <summary>
/// executionLocation getter
/// The location where a component Artifact executes. This may be a local or remote
/// location.
/// </summary>
QString DeploymentSpecification::executionLocation() const {
    return executionLocation_;
}

/// <summary>
/// executionLocation setter
/// The location where a component Artifact executes. This may be a local or remote
/// location.
/// </summary>
void DeploymentSpecification::setExecutionLocation(const QString& value) {
    executionLocation_ = value;
}

} // namespace uml
